<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/12/13
  Time: 16:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <script src="/js/jquery-1.8.2.min.js"></script>
    <script src="/js/fileupload.js"></script>
    <script src="/My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="/css/css.css">
    <link rel="stylesheet" href="/css/img.css">
</head>
<body>
<form action="list" method="post">
    <input type="hidden" name="pageNum" id="pageNum"><br>

</form>
<button onclick="xz()">添加</button>
<button onclick="ps()">批量删除</button>
<table>
    <tr>
        <td>
            <input type="checkbox" onclick="qx()" id="qq">
            全选
        </td>
        <td>编号</td>
        <td>商品名称</td>
        <td>商品品牌</td>
        <td>规格型号</td>
        <td>价格</td>
        <td>上架时间</td>
        <td>图片</td>
        <td>操作</td>
    </tr>
    <c:forEach var="s" items="${page.list}">
        <tr>
            <td>
                <input type="checkbox" class="ck" value="${s.sid}">
            </td>
            <td>${s.sid}</td>
            <td>${s.sname}</td>
            <td>${s.brandName}</td>
            <td>${s.sstyle}</td>
            <td>￥${s.sprice}</td>
            <td>${s.stime}</td>
            <td>
                <img src="${s.spic}" alt="正在加载" width="70px">
            </td>
            <td>
                <button onclick="del(${s.sid})">删除</button>
                <button onclick="upt(${s.sid})">修改</button>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="9">
            <a href="javaScript:go(1)">首页</a>
            <a href="javaScript:go(${page.isFirstPage?1:page.prePage})">上一页</a>
            <a href="javaScript:go(${page.isLastPage?page.pages:page.nextPage})">下一页</a>
            <a href="javaScript:go(${page.pages})">尾页</a>
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
            当前第${page.pageNum}页&emsp;共${page.pages}页
        </td>
    </tr>
</table>
</body>
<script>
    function xz() {
        location = "toadd";
    }
    function upt(sid) {
        location = "toupdate?sid="+sid;
    }
    function qx() {
        if ($("#qq").attr("checked")){
            $(".ck:checkbox").prop("checked",true)
        }else {
            $(".ck:checkbox").prop("checked",false)
        }
    }
    function go(pageNum) {
        $("#pageNum").val(pageNum)
        $("form").submit()
    }
    function del(sid) {
        if (confirm("确定要删除编号为:"+sid+"的数据吗?")){
            $.ajax({
                url:"del",
                type:"post",
                data:{"sid":sid},
                dataType:"json",
                success:function (a) {
                    if (a>0){
                        alert("删除成功")
                        location = "list";
                    }
                }
            })
        }
    }
    function ps() {
        var sid = "";
        $(".ck:checked").each(function () {
            var zhi = $(this).val();
            sid += ","+zhi;
        })
        sid=sid.substring(1);
        if (confirm("确定要批量删除编号为:"+sid+"的数据吗?")){
            alert("批量删除成功")
            location = "del?sid="+sid;
        }
    }
</script>
</html>
